<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>商品列表</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<!--公共JS开始-->
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.timer.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<!--公共JS结束-->
<!--数据列表插件开始-->
<link href="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.ui.position.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.js"></script>
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Css/etgrid.css">
<script src="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Js/etgrid.js"></script>
<!--数据列表插件结束-->
<!--ZTree开始-->
<link rel="stylesheet" href="{$NOW_THEME_URL}/Assets/Plugins/ZTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<include file="treeColumn" />
<script type="text/javascript" src="{$NOW_THEME_URL}/Assets/Plugins/ZTree/js/jquery.ztree.core-3.5.js"></script>
<!--ztree结束-->
<style type="text/css">
	body {
		overflow:hidden;
	}
	.table_box {
	}
</style>
</head>

<body>
	<div class="page_header">
		<div class="table_tool">
			<ul class="clearfix">			
				<li class="productDel btn"><i class="icon-remove"></i> 批量删除</li>
				<li class="line"></li>
				<li class="openwin btn" etitle="新增商品" eheight="400px" ewidth="900px" ehref="{:U('Product/add')}"  id="Product_add"><i class="icon-plus"></i>新增商品</li>
				<li class="line"></li>
				<li class="openwin btn" etitle="商品套餐（请先选择套餐产品）" eheight="400px" ewidth="850px" ehref="{:U('Product/addPackage')}"  id="Product_addPackage"><i class="icon-plus"></i>商品套餐</li>
				<li class="line"></li>
				<li class="productEdit btn">
					<i class="icon-asterisk"></i> 上下架管理
					<ul class="submenu">
						<li toid="added"><i class="icon-caret-right"></i> 商品上架</li>
						<li toid="offed"><i class="icon-caret-right"></i> 商品下架</li>
					</ul>
				</li>
				<li class="line"></li>
				<li class="productPrice btn">
					<i class="icon-asterisk"></i> 特价管理
					<ul class="submenu">
						<li toid="openSpecial"><i class="icon-caret-right"></i> 特价启用</li>
						<li toid="closeSpecial"><i class="icon-caret-right"></i> 特价停用</li>
					</ul>
				</li>
				<li class="line"></li>
				<li class="memberFrost btn">
					<i class="icon-asterisk"></i> 商品导入导出
					<ul class="submenu">
						<li toid="frost"><i class="icon-caret-right"></i> 商品批量导入</li>
						<li toid="thaw"><i class="icon-caret-right"></i> 商品批量导出</li>
					</ul>
				</li>
			</ul>
		</div>
		<div class="search_box">
			<input type="text" id="keywords" class="form_ele w300" placeholder="请输入商品名称、商品编号搜索"/>
			<select name="typeid" id="typeid">
				<option value="">商品类型</option>
				<option value="1">计件商品</option>
				<option value="2">计量商品</option>
				<option value="3">计次商品</option>
				<option value="4">计时商品</option>
			</select>
			<select name="package" id="package">
				<option value="">套餐商品</option>
				<option value="1">是</option>
				<option value="2">否</option>
			</select>
			<select name="isspecial" id="isspecial">
				<option value="">特价商品</option>
				<option value="1">是</option>
				<option value="2">否</option>
			</select>
			<select name="isdiscount" id="isdiscount">
				<option value="">折扣商品</option>
				<option value="1">是</option>
				<option value="2">否</option>
			</select>
			<select name="isdel" id="isdel">
				<option value="">商品状态</option>
				<option value="2">上架</option>
				<option value="3">下架</option>
			</select>
			<select name="brandid" id="brandid">
				<option value="">商品品牌</option>
				<volist name="brands" id="v">
					<option value="{$v.id}">{$v.title}</option>
				</volist>
			</select>
			<span id="doSearch" class="doSearch">
				<i class="icon-search"></i> 搜索
			</span>
			<span id="doSearch" class="doSearch clearSearch">重置搜索条件</span>
		</div>
	</div>
	<div class="yhlist clearfix">
		<ul id="tree" class="ztree" style="width:170px;overflow:auto;float:left;"></ul>
		<div class="table_box" style="float:left;border-left:1px solid #999;">
		</div>
	</div>
</body>
<script type="text/javascript">
	var listConfig = {
			blockBox : '.table_box',
			blockBoxHeight : 'window',
			blockBoxWidth : 'adaptive',
			adaptiveFixedWidth : '181',
			jsonUrl : '__URL__/index',
			where : '',
			getWhere : function(){
				var select = {};
				
				var keywords   = $('#keywords').val();
				var typeid     = $('#typeid').val();
				var package    = $('#package').val();
				var isspecial  = $('#isspecial').val();
				var isdiscount = $('#isdiscount').val();
				var isdel      = $('#isdel').val();
				var brandid    = $('#brandid').val();
				
				if(keywords){  select['keywords']    = $('#keywords').val()};
				if(typeid){    select['typeid']      = $('#typeid').val()};
				if(package){   select['package']     = $('#package').val()};
				if(isspecial){ select['isspecial']   = $('#isspecial').val()};
				if(isdiscount){select['isdiscount']  = $('#isdiscount').val()};
				if(isdel){     select['isdel']       = $('#isdel').val()};
				if(brandid){   select['brandid']     = $('#brandid').val()};
				
				return select;
			},
			widthType : 'thw', //thw-标题标准宽度、tdw-数据单元标准宽度、auto-随数据单元宽度
			pageNum : 10,
			nowPage : 1,
			orderName : "addtime",
			orderDirection : "desc",
			dataContextMenuOpen: true, //是否开启数据行右键菜单
			dataContextMenu: function(){
				$.contextMenu({
					selector: '.et_tbody tr',
					items: {
						"edit": {
							name: "修改商品", 
							icon: "edit",
							callback: function(key, options) {
								var href   = '__URL__/edit/id/'+$(this).attr('rowid');
								var width  = '900px';
								var height = '500px';
								var title  = '修改商品';
								openDialog('Product_edit',href,width,height,title);
							}
						},
						"delete": {
							name: "删除", 
							icon: "edit",
							callback: function(key, options) {
								
								var val = $(this).attr('rowid');
								$.get("{:U('Product/del')}",{val:val},function(data){
									if(data.status==1){
										$('.et_tfoot .page_refresh').click(); //刷新加载
									}else{
										windowApi.lhgdialog.alert(data.info,function(){return;});
									}
								})
							}
						},
						"copy": {
							name: "商品复制新建", 
							icon: "add",
							callback: function(key, options) {
								var href   = '__URL__/add/id/'+$(this).attr('rowid');
								var width  = '900px';
								var height = '500px';
								var title  = '新增商品';
								openDialog('Product_add',href,width,height,title);
							}
						},
					}
				});
			},
			colModel : [
				{
					display : 'checkbox',
					name : 'id',
					sortable : true,
					myclass : 'center',
					edit : false,
					width : '20px'
				},
				{
					display : '商品编号',
					name : 'pno',
					sortable : false,
					myclass : 'center',
					edit : false
				},
				{
					display : '商品名称',
					name : 'title',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '所属品牌',
					name : 'brand',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '成本价格',
					name : 'mprice',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '销售价格',
					name : 'sprice',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '状态',
					name : 'isdel',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '特价',
					name : 'isspecial',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '套餐',
					name : 'package',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '添加时间',
					name : 'addtime',
					sortable : false,
					myclass : 'center',
					edit : false
				}
			]
		};
	
	//实例化列表
	var tableList = $('.table_box').EtGrid(listConfig);
	//tableList.erefresh();
	
	//搜索
 	$('#doSearch').on('click',function(){
		
		var where = tableList.config.getWhere();
		
		tableList.config.where = where;
		tableList.search();
	});
	
	//重置搜索条件
	$('.clearSearch').on('click',function(){
		$('#keywords').val('');
		$('#typeid').val('');
		$('#package').val('');
		$('#isspecial').val('');
		$('#isdiscount').val('');
		$('#isdel').val('');
		$('#brandid').val('');
	})
	
	//批量删除
	$('.productDel').on('click',function(){

		var val = tableList.getChecked();
		var msg = "确认要将选中的商品删除吗？";
		
		if(val){
			windowApi.lhgdialog.confirm(msg, function(){
				$.post("{:U('Product/del')}",{val:val},function(data){
					if(data.status==1){
						$('.et_tfoot .page_refresh').click(); //刷新加载
					}else{
						windowApi.lhgdialog.alert(data.info,function(){return;});
					}
				});
			},function(){
				return;
			});
		}else{
			windowApi.lhgdialog.alert('请选择需要删除的商品！',function(){return;});
		}
		
	});
	
	//移动到分组
	$('.memberGroup .submenu>li').on('click',function(){
		var val = '';
		$('.et_tbody .chk_item:checked').each(function(index, element) {
			if(val){
				val += ','+$(this).val();
			}else{
				val += $(this).val();
			}
		});
		
		alert('将Id为'+val+'的数据移动到Id为'+$(this).attr('toid')+'的会员分组');
	});
	
	//商品特价启用、停用
	$('.productPrice .submenu>li').on('click',function(){
		var val  = tableList.getChecked();
		var toid = $(this).attr('toid');
		var url  = toid=='openSpecial'?"{:U('Product/openSpecial')}":"{:U('Product/closeSpecial')}";
		
		$.get(url,{val:val},function(data){
			if(data.status==1){
				$('.et_tfoot .page_refresh').click(); //刷新加载
			}else{
				windowApi.lhgdialog.alert(data.info,function(){return;});
			}
		})
	});
	
	//商品上下架
	$('.productEdit .submenu>li').on('click',function(){
		var val  = tableList.getChecked();
		var toid = $(this).attr('toid');
		var url  = toid=='added'?"{:U('Product/added')}":"{:U('Product/offed')}";
		
		$.get(url,{val:val},function(data){
			if(data.status==1){
				$('.et_tfoot .page_refresh').click(); //刷新加载
			}else{
				windowApi.lhgdialog.alert(data.info,function(){return;});
			}
		})
	});
	
	//打开统计图表
	$('.memberChart').on('click',function(){
		var href = 'memberAdd.html?id='+$(this).attr('rowid');
		var width = '900px';
		var height = '500px';
		var title = '统计图表';
		openDialog('memberChart',href,width,height,title);
	});
</script>
</html>
